package com.example.reactordemo.controller;

import com.example.reactordemo.domain.Student;
import com.example.reactordemo.service.SpringWebFluxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/test/webflux")
public class SpringWebFluxController {

    @Autowired
    SpringWebFluxService springWebFluxService;

    /** Flux和Mono区别
     *  Flux发送出0~N个
     *  Mono发送出0~1个
     *  请自行百度学习具体区别
     */

    /**
     * 测试r2dbc连接mysql数据库-查询
     */
    @GetMapping("/testR1")
    public Flux<Student> Test() {
        return springWebFluxService.findAll();
    }

    /**
     * 测试r2dbc连接mysql数据库-新增
     */
    @PostMapping("/testR3")
    public Mono<Integer> Test2(@RequestBody Student student) {
        System.out.println(student);
        return springWebFluxService.insertDefined(student);
    }

}